﻿Partial Public Class ucReaderSettings
    

    Private Sub buttonSave_Click(ByVal sender As System.Object, ByVal e As System.Windows.RoutedEventArgs) Handles buttonSave.Click
        My.Settings.localLocation = textboxBackupFilesLocation.Text
        My.Settings.remoteLocation = textboxReaderFilesLocation.Text
        My.Settings.retainFilesonReader = cbRemoveFilesFromReader.IsChecked
        My.Settings.Save()
        RibbonMain.isDirty = False
        enablebuttons(RibbonMain.isDirty)
        MsgBox("Your settings were saved successfully.", MsgBoxStyle.OkOnly, "Save...")
    End Sub

    Sub enablebuttons(ByVal enable As Boolean)
        If Not buttonCancel Is Nothing Then
            buttonCancel.IsEnabled = enable
            buttonSave.IsEnabled = enable
        End If
        
    End Sub

    Private Sub ucReaderSettings_Loaded(ByVal sender As Object, ByVal e As System.Windows.RoutedEventArgs) Handles Me.Loaded
        textboxBackupFilesLocation.Text = My.Settings.localLocation
        textboxReaderFilesLocation.Text = My.Settings.remoteLocation
        cbRemoveFilesFromReader.IsChecked = My.Settings.retainFilesonReader
        RibbonMain.isDirty = False
        enablebuttons(RibbonMain.isDirty)
    End Sub

    Private Sub buttonCancel_Click(ByVal sender As System.Object, ByVal e As System.Windows.RoutedEventArgs) Handles buttonCancel.Click
        textboxBackupFilesLocation.Text = My.Settings.localLocation
        textboxReaderFilesLocation.Text = My.Settings.remoteLocation
        cbRemoveFilesFromReader.IsChecked = My.Settings.retainFilesonReader
        RibbonMain.isDirty = False
        enablebuttons(RibbonMain.isDirty)
    End Sub

    Private Sub buttonBrowseReader_Click(ByVal sender As System.Object, ByVal e As System.Windows.RoutedEventArgs) Handles buttonBrowseReader.Click
        Dim ownedWindow As New BrowseDevice
        Try
            ownedWindow.Path = textboxReaderFilesLocation.Text
            ownedWindow.ShowDialog()
            If ownedWindow.OkCancel = "OK" Then
                textboxReaderFilesLocation.Text = ownedWindow.Path
            End If
        Catch ex As Exception
            ownedWindow.Close()
            MsgBox("Please check if your device is connected.", MsgBoxStyle.OkOnly, "Connecting to device...")
        End Try
    End Sub

    Private Sub buttonBrowseBackup_Click(ByVal sender As System.Object, ByVal e As System.Windows.RoutedEventArgs) Handles buttonBrowseBackup.Click
        Dim dlg As New System.Windows.Forms.FolderBrowserDialog
        dlg.SelectedPath = textboxBackupFilesLocation.Text
        If dlg.ShowDialog() = Forms.DialogResult.OK Then
            textboxBackupFilesLocation.Text = dlg.SelectedPath
        Else
            textboxBackupFilesLocation.Text = My.Settings.localLocation
        End If
    End Sub



    Private Sub textboxBackupFilesLocation_TextChanged(ByVal sender As Object, ByVal e As System.Windows.Controls.TextChangedEventArgs) Handles textboxBackupFilesLocation.TextChanged
        RibbonMain.isDirty = True
        enablebuttons(RibbonMain.isDirty)
    End Sub

    Private Sub cbRemoveFilesFromReader_Checked(ByVal sender As Object, ByVal e As System.Windows.RoutedEventArgs) Handles cbRemoveFilesFromReader.Checked, cbRemoveFilesFromReader.Unchecked
        RibbonMain.isDirty = True
        enablebuttons(RibbonMain.isDirty)
    End Sub

    
End Class
